import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class CoreService {
  constructor() {}

  /**
   * 判断在当前页删除一个项目后，是否需要变动页索引为上一页
   * @param pageIndex 页索引
   * @param currentPageItems 当前页项目数
   */
  afterDeletingPag(pageIndex: number, currentPageItems: number) {
    currentPageItems--;
    if (currentPageItems === 0) {
      if (pageIndex > 1) {
        pageIndex--;
      }
    }

    return {
      pageIndex,
      currentPageItems,
    };
  }
}
